package com.test.base.api;

import com.test.base.dao.NideshopGoodsAttributeDao;
import com.test.base.dao.NideshopGoodsDao;
import com.test.base.dao.NideshopGoodsGalleryDao;
import com.test.base.dao.NideshopGoodsIssueDao;
import com.test.base.entity.NideshopCollect;
import com.test.base.entity.NideshopGoods;
import com.test.base.entity.NideshopGoodsAttributeExt;
import com.test.base.entity.NideshopGoodsGallery;
import com.test.base.service.GoodsService;
import com.test.base.utils.Assist;
import com.test.base.vo.api.SkuVo;
import com.test.base.vo.common.ResultData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 *
 */

@RestController
@RequestMapping(value = "api/goods")
@Api(description = "商品API")
public class GoodsApi {
    @Autowired
    private NideshopGoodsDao nideshopGoodsDao;
    @Autowired
    private NideshopGoodsGalleryDao nideshopGoodsGalleryDao;
    @Autowired
    private NideshopGoodsAttributeDao nideshopGoodsAttributeDao;
    @Autowired
    private GoodsService goodsService;

    @ApiOperation(value = "获取商品", notes = "")
    @RequestMapping(value = "/index", method = RequestMethod.GET)
    @ResponseBody
    public ResultData index() {
        List<NideshopGoods> nideshopGoods = nideshopGoodsDao.selectNideshopGoods(null);
        return ResultData.success(nideshopGoods);
    }

    @ApiOperation(value = "获取商品", notes = "")
    @RequestMapping(value = "/sku", method = RequestMethod.GET)
    @ResponseBody
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "商品ID", paramType = "query", required = true, dataType = "Long")
    })
    public ResultData sku(Long id) {
        SkuVo skuVo = new SkuVo();
        skuVo.setProductList(goodsService.getProductList(id));
        skuVo.setSpecificationList(goodsService.getSpecificationList(id));
        return ResultData.success(skuVo);
    }


    @ApiOperation(value = "商品详情页数据", notes = "")
    @RequestMapping(value = "/detail", method = RequestMethod.GET)
    @ResponseBody
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "商品ID", paramType = "query", required = true, dataType = "Long")
    })
    public ResultData detail(Long id) {
        NideshopGoods info = nideshopGoodsDao.selectNideshopGoodsById(id);
        Assist goodsGallery = new Assist();
        goodsGallery.setRequires(Assist.andEq("goods_id",id));
        goodsGallery.setRowSize(4);
        goodsGallery.setStartRow(0);
        List<NideshopGoodsGallery> gallery =nideshopGoodsGalleryDao.selectNideshopGoodsGallery(goodsGallery);
        List<NideshopGoodsAttributeExt> attribute = nideshopGoodsAttributeDao.selectNideshopGoodsAttributeByGoodsId(id);

        return ResultData.success();
    }


}
